#include <stdio.h>
#include <stdlib.h>
struct node
{
	int data;
	struct node *next;
};
int main(){
	struct node*t,*p,*q,*head;
	int i,n,a;
	head=NULL;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		p=(struct node *)malloc(sizeof(struct node));
		p->data=a;
		p->next=NULL;
		if(head==NULL) head=p;
		else q->next=p;	
		q=p;
	}
	t=head;
	scanf("%d",&a);
	while(t!=NULL){
		if(t->next==NULL ||t->next->data >a){
			p=(struct node*)malloc(sizeof(struct node));
			p->data=a;
			p->next=t->next;
			t->next=p;
			break;
		}
	t=t->next;
		
	}
	t=head;
	while(t!=NULL){
		printf("%d ",t->data);
		t=t->next;
	}
	free(t);
	free(p);
	free(q);
	free(head);
	return 0;
}
